package com.zyh.homework.test1.impl;

import com.zyh.homework.test1.Comparable;
import com.zyh.homework.test1.domain.Student;

import java.util.List;

/**
 * @Author zyh
 * @Date 2024/7/31 16:55
 * @Description
 */

public class ComparableImpl implements Comparable {
    //排序，年龄从小到大
    @Override
    public List<Student> sortAge(List<Student> list) {
        for (int i = 0; i < list.size() - 1; i++) {
            for (int j = 0; j < list.size() - 1 - i; j++) {
                if (list.get(j).getAge()>list.get(j+1).getAge()){
                    Student temp=list.get(j);
                    list.set(j,list.get(j+1));
                    list.set(j+1,temp);
                }
            }
        }
        return list;
    }

    //成绩从大到小排序
    @Override
    public List<Student> sortScore(List<Student> list) {
        for (int i = 0; i < list.size() - 1; i++) {
            for (int j = 0; j < list.size() - 1 - i; j++) {
                if (list.get(j).getScore()<list.get(j+1).getScore()){
                    Student temp=list.get(j);
                    list.set(j,list.get(j+1));
                    list.set(j+1,temp);
                }
            }
        }
        return list;
    }
}
